package com.example.demo.constant;



import java.util.HashMap;
import java.util.Map;

public enum ErrorCode implements BaseErrorInfoInterface {


    SUCCESS(1000,"成功!"),
    BODY_NOT_MATCH(1101,"非法请求数据!"),
    SIGNATURE_NOT_MATCH(1200,"暂无缓存信息"),
    NOT_FOUND(1201,"缓存服务宕机!"),
    INTERNAL_SERVER_ERROR(1202,"请求超时!"),
    SERVER_BUSY(1203,"第三方服务异常!");
    // 以上是枚举的成员，必须先定义，而且使用分号结束
    private final String description;
    private final int code;
    ErrorCode(int code,String description) {
        this.description = description;
        this.code=code;
    }
    //获取code
    @Override
    public Integer getCode(){
        return code;
    }
    //获取描述
    @Override
    public String getDescription(){
        return description;
    }


    //返回map 详细描述
    public Map DescriptionMap() {
        Map<String,Object> map= new HashMap<>();
        map.put(String.valueOf(code),description);
        return map;
    }
    //根据code获取描述
    public static Map getDescriptionByCode(Integer code) {
        ErrorCode[] values = ErrorCode.values();
        for (ErrorCode value : values) {
            if (value.code == code) {
                Map<String,Object> map = new HashMap();
                map.put(String.valueOf(value.code),value.description);
                return map;
            }
        }
        return null;
    }
}
